package tankproject;

import java.awt.*;

class Bullet {

    private Point position;
    private Point mouse;
    private final int SPEED = 2;
    private double rotation; // In radians

    public Bullet(Game game, int x, int y) {
        position = new Point(x, y);
        mouse = game.getMousePosition();
        rotation = Math.atan2(mouse.y - position.y,
                mouse.x - position.x);
    }

    public void paint(Graphics g) {
        move();
        g.setColor(Color.ORANGE);
        g.fillOval(position.x, position.y, 15, 15);
    }

    public Point getPosition() {
        return position;
    }

    private void move() {
        float distancex = (float) Math.cos(rotation);
        float distancey = (float) Math.sin(rotation);
        position.x += distancex * SPEED * 2;
        position.y += distancey * SPEED * 2;
    }


}
